/*
 * Created by SharpDevelop.
 * User: MyWife
 * Date: 9/13/2010
 * Time: 4:43 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Reflection;

namespace popLib.CustomeControl
{
	/// <summary>
	/// Description of CustomPrintPreviewDialog.
	/// </summary>
	public class CustomPrintPreviewDialog :System.Windows.Forms.PrintPreviewDialog
	{
		private ToolStripButton myPrintButton;
		private ToolStripButton printButton;
		public CustomPrintPreviewDialog():base()
		{
			Type t = typeof ( PrintPreviewDialog );
			FieldInfo fi = t.GetField ( "toolStrip1", BindingFlags.Instance | BindingFlags.NonPublic );
			FieldInfo fi2 = t.GetField ( "printToolStripButton", BindingFlags.Instance | BindingFlags.NonPublic );
			ToolStrip toolStrip1 = ( ToolStrip ) fi.GetValue ( this );
			printButton = ( ToolStripButton ) fi2.GetValue ( this );
			printButton.Visible = false;
			myPrintButton = new ToolStripButton( );
			myPrintButton.ToolTipText = printButton.ToolTipText;
			myPrintButton.ImageIndex = 0;
			 
			ToolStripItem [ ] oldButtons = new ToolStripItem [ toolStrip1.Items.Count ];
			for ( int i = 0; i < oldButtons.Length; i++ )
				oldButtons [ i ] = toolStrip1.Items [ i ];
			 
			toolStrip1.Items.Clear ( );
			toolStrip1.Items.Add ( myPrintButton );
			
			for ( int i = 0; i < oldButtons.Length; i++ )
				toolStrip1.Items.Add ( oldButtons [i] );
			
			toolStrip1.ItemClicked += new ToolStripItemClickedEventHandler ( toolBar1_Click );
		}
		 
		private void toolBar1_Click ( object sender, ToolStripItemClickedEventArgs eventargs )
		{
			if ( eventargs.ClickedItem == myPrintButton )
			{
				PrintDialog printDialog1 = new PrintDialog ( );
				
				printDialog1.AllowCurrentPage = true;
				printDialog1.AllowSelection = true;
				printDialog1.AllowSomePages = true;
				printDialog1.UseEXDialog = true;
				
				printDialog1.Document = this.Document;
				if ( printDialog1.ShowDialog ( ) == DialogResult.OK )
					this.Document.Print ( );
			}
		}
	}
}
